#pragma once
#include <string>
enum class ImageFormat
{
    LDR,
    HDR
};

class Image {
public:
    Image(int width, int height, int channels, ImageFormat format);
    ~Image();

    Image(const Image&) = delete;
    Image& operator=(const Image&) = delete;

    static Image* Load(const std::string& filename);
    void Save(const std::string& filename);

    void FlipH();
    void FlipV();

    unsigned char* GetLdrPixel(int row, int col);
    float* GetHdrPixel(int row, int col);

    void SetPixel(int row, int col, const float* value); 
    void SetPixel(int row, int col, const unsigned char* value); 

    const unsigned char* GetLdrBuffer() const { return ldrBuffer; }
    void SetLdrBuffer(unsigned char* buffer) { ldrBuffer = buffer; }
    void SetOwnsMemory(bool owns) { ownsMemory = owns; }

    int GetWidth() const { return width; }
    int GetHeight() const { return height; }

private:

    static std::string GetExtension(const std::string& filename);

    static Image* LoadTGA(const std::string& filename);
    static Image* LoadHDR(const std::string& filename);

    void SaveTGA(const std::string& filename);
    void SaveHDR(const std::string& filename);

private:
    ImageFormat format;
    int width, height, channels;

    unsigned char* ldrBuffer;
    float* hdrBuffer;

    bool ownsMemory;
};
